package com.xuan.commons.api;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author renzhengxuan
 * @date 2021/5/24
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private boolean success;
    private T date;

    public static Result<Object> status(boolean flag){
        Result result = new Result();
        if(flag){
            result.code=200;
            result.msg="操作成功";
            result.success=true;
        }else{
            result.code=500;
            result.msg="操作失败";
            result.success=false;
        }
        return result;
    }

    public static Result<Object> ok(Object date){
        Result result = new Result();
        result.code=200;
        result.msg="操作成功";
        result.success=true;
        result.date=date;
        return result;
    }

    public static Result<Object> error(String msg){
        Result result = new Result();
        result.code=500;
        result.msg=msg;
        result.success=false;
        return result;
    }
    public static Result<Object> fail(String msg){
        Result result = new Result();
        result.code=500;
        result.msg=msg;
        result.success=false;
        return result;
    }
}
